package com.skycode7.servlet;

import com.skycode7.dao.AdminDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/adminDel.jsp")
public class AdminDelServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        String User = (String) req.getSession().getAttribute("User");
        if (User == null || User.equals("")) {
            resp.sendRedirect("login.jsp");
            return;//页面显示和重定向只能生效一个
        }
        req.setCharacterEncoding("UTF-8");
        String adminId = req.getParameter("AdminId");
        int result = (new AdminDao()).delete(Integer.parseInt(adminId));
        if (result > 0) {
            resp.sendRedirect("adminUser.jsp");
        } else {
            req.getRequestDispatcher("WEB-INF/error.jsp").forward(req, resp);
        }
    }
}
